﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_JGXX_Manager : System.Web.UI.Page
{
    public int JGID
    {
        get { return Convert.ToInt32(ViewState["_JGID"]); }
        set { ViewState["_JGID"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            JGID = DongDong.Common.Misc.GetQueryStringAsInt("JGID");
            if (JGID != 0)
            {
                lvDate.DataSource = JGXX.GetByID(JGID);
                lvDate.DataBind();
            }
            PopulateDrop();
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateJGXX();
    }

    // 删除
    protected void lvDate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int KeyID = DongDong.Common.Misc.ConvertToInt(lvDate.DataKeys[e.ItemIndex].Value);
        JGXX.BadDelete(KeyID);
        lvDate.EditIndex = -1;
        PopulateJGXX();
    }

    // 查询
    public void PopulateJGXX()
    {
        lvDate.DataSource = JGXX.GetAllByCondition(DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpQu.SelectedValue), txtAddress.Text, txtJFName.Text, txtDes.Text, txtJFGM.Text, DongDong.Common.Misc.ConvertToInt(drpJGType.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpJGSort.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpRZLevel.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpRZStatus.SelectedValue));
        lvDate.DataBind();
    }

    // 绑定下拉框
    public void PopulateDrop()
    {
        drpJGType.PopulateFromEnum<JGXX.typeJG>();
        drpJGType.Items.Insert(0, new ListItem("请选择", "999"));
        drpJGSort.PopulateFromEnum<JGXX.sortJG>();
        drpJGSort.Items.Insert(0, new ListItem("请选择", "999"));
        drpRZLevel.PopulateFromEnum<JGXX.levelRZ>();
        drpRZLevel.Items.Insert(0, new ListItem("全部", "999"));
        drpRZStatus.PopulateFromEnum<JGXX.statusRZ>();
        drpRZStatus.Items.Insert(0, new ListItem("全部", "999"));

        drpSheng.DataSource = S_Province.GetAll();
        drpSheng.DataValueField = "ProvinceID";
        drpSheng.DataTextField = "ProvinceName";
        drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpShi.Items.Insert(0, new ListItem("请选择", "0"));

        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        drpShi.DataSource = S_City.GetAllByCondition(ParentID, "");
        drpShi.DataValueField = "CityID";
        drpShi.DataTextField = "CityName";
        drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        drpQu.DataSource = S_District.GetAllByCondition(ParentID, "");
        drpQu.DataValueField = "DistrictID";
        drpQu.DataTextField = "DistrictName";
        drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    // 获得省市区名称
    public string GetShengShiQuName(object sheng, object shi, object qu)
    {
        string Return = "暂无资料";
        Return = S_District.GetPName_CName_RNameByPID_CID_RID(sheng, shi, DongDong.Common.Misc.ConvertToInt(qu));
        return Return;
    }

    // 获得能力认证
    public string GetRZLEVEL(object OID)
    {
        string Return = "暂无资料";
        //Return = S_District.GetPName_CName_RNameByPID_CID_RID(sheng, shi, DongDong.Common.Misc.ConvertToInt(qu));
        return Return;
    }

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateJGXX();
    }
}